<?php
include 'connect.php';

// 获取表单提交的数据
$username = $_POST['username'];
$password = $_POST['password'];

// 查询数据库
$sql = "SELECT * FROM member WHERE username='$username' AND password='$password'";
$result = mysqli_query($link, $sql);

if ($result && mysqli_num_rows($result) > 0) {
    $row = mysqli_fetch_array($result);
    
    echo "登录成功";
    
    // 设置 Cookie
    setcookie('username', $username, time() + (86400 * 30), "/"); // 保存30天
    setcookie('user_id', $row['id'], time() + (86400 * 30), "/"); // 假设用户ID字段为id
    
    // 可以选择同时设置 session
    session_start();
    $_SESSION['username'] = $username;
    $_SESSION['user_id'] = $row['id'];
    // 重定向到会员中心页面
    header("Location:memberCenter.php");
} else {
    echo "登录失败：用户名或密码错误";
}
?>